package com.qf.servlet;

import com.qf.entity.Admin;
import org.apache.commons.io.IOUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;

/**
 * description: 这是一行注释 有些了一些东西
 * description: 主分支加的一些东西
 * author: Ken
 * 公众号：Java架构栈
 */
@WebServlet(urlPatterns = "/headershow")
public class HeaderShowServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //直接在session中获取当前用户的头像名称
        Admin admin = (Admin) req.getSession().getAttribute("login_user");
        String header = admin.getHeader();
        System.out.println("------>获取用户头像的名称：" + header);

        //头像的File对象
        File file = new File(RegisterFileServlet.uploaderPath + header);
        try (
            InputStream in = new FileInputStream(file);
            OutputStream out = resp.getOutputStream();
        ) {
            IOUtils.copy(in, out);
        }
    }
}
